// pages/order/order.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        addressList:[],
        orderList:[
            {
                id:'',
                picUrl:'/images/1.png',
                name:'追源深山土蜂蜜追源深深山土蜂蜜追源深山土蜂蜜',
                price:88.00,
                size:'1斤装',
                flavor:'',
                num:1
            },
            {
                picUrl:'/images/1.png',
                name:'追源酸枣糕',
                price:19.50,
                size:'250克/袋',
                flavor:'',
                num:1
            }
        ],
        postPrice:0.0,
        total:196.00
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let shareid = options.shareid;

        if (shareid){
            wx.setStorageSync('shareid', shareid);
        }
        let product = JSON.parse(options.product);
        let orderlist = this.data.orderList;

        console.log(product);
        orderlist.push(product);
        this.setData({
            orderList:orderlist
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        let postprice = this.data.postPrice;
        let addresslist = wx.getStorageSync('addressList');
        let total = 0;
        let orderlist = this.data.orderList;

        for (let i of orderlist){
            total += i.price;
        }

        if (total < 39){
            postprice = 5;
            total += postprice;
            postprice = postprice.toFixed(2);
            total = total.toFixed(2);
        }
        this.setData({
            addressList:addresslist,
            total:total,
            postPrice:postprice
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title:'sharetest',
            path:'/pages/index/index?shareid=' + '54185418'
        }
    },
    /**
    * (修改地址)
    * @徐志鹏
    * @2021-2-10 
    */
    select_adderss:function(){
        wx.navigateTo({
          url: '/pages/ucenter/address/address',
        })
    }
})